From a56b74a95003b73604266a4172cb67961db28abd Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Mon, 14 Jan 2008 18:44:29 +0000 Subject: [PATCH] * Add caching to the AJAX search --- RELEASE-NOTES | 3 ++- includes/AjaxFunctions.php | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1657d6b934..6291317959 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -131,7 +131,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN edit, via the parameter 'bot'. (Default: '1') * (bug 12536) User should be able to get MediaWiki version from any page * (bug 12622) A JavaScript constant to declare whether api.php is available - +* Add caching to the AJAX search + === Bug fixes in 1.12 === diff --git a/includes/AjaxFunctions.php b/includes/AjaxFunctions.php index b004cfc20f..d630461741 100644 --- a/includes/AjaxFunctions.php +++ b/includes/AjaxFunctions.php @@ -73,8 +73,10 @@ function code2utf($num){ return ''; } +define( 'AJAX_SEARCH_VERSION', 1 ); //AJAX search cache version + function wfSajaxSearch( $term ) { - global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks; + global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks, $wgMemc; $limit = 16; $sk = $wgUser->getSkin(); @@ -84,6 +86,14 @@ function wfSajaxSearch( $term ) { $term = $wgContLang->ucfirst( $term ); $term_title = Title::newFromText( $term ); + $memckey = wfMemcKey( 'ajaxsearch', md5( $term_title->getFullText() ) ); + $cached = $wgMemc->get($memckey); + if( is_array( $cached ) && $cached['version'] == AJAX_SEARCH_VERSION ) { + $response = new AjaxResponse( $cached['html'] ); + $response->setCacheDuration( 30*60 ); + return $response; + } + $r = $more = ''; $canSearch = true; if( $term_title && $term_title->getNamespace() != NS_SPECIAL ) { @@ -147,10 +157,10 @@ function wfSajaxSearch( $term ) { . '' . $more; } - $response = new AjaxResponse( $html ); + $wgMemc->set( $memckey, array( 'version' => AJAX_SEARCH_VERSION, 'html' => $html ), 30 * 60 ); + $response = new AjaxResponse( $html ); $response->setCacheDuration( 30*60 ); - return $response; } -- 2.20.1